from rest_framework import serializers
from rest_framework.pagination import PageNumberPagination

from apps.recruits.models import Enterprise, Recruit, City

class PagNun(PageNumberPagination):
    page_size = 4
    page_size_query_param = 'pagesize'
    max_page_size = 4


# 简单企业信息数据序列化器
class Enterpriseserializer(serializers.ModelSerializer):
    """企业信息数据序列化器"""
    recruits = serializers.PrimaryKeyRelatedField(label='招聘职位', read_only=True, many=True)
    class Meta:
        model = Enterprise
        fields = ['id', 'name', 'labels', 'logo', 'recruits', 'summary']


class RecruitSerializer(serializers.ModelSerializer):
    """职位数据序列化器"""
    enterprise = Enterpriseserializer()
    # enterprise = Enterpriseserializer(serializers.ModelSerializer)

    class Meta:
        model = Recruit
        fields = '__all__'


class CitySerializer(serializers.Serializer):
    """城市数据序列化器"""

    class Meta:
        model = City
        fields = '__all__'


class Enterpriseserializerez(serializers.ModelSerializer):
    """企业信息数据序列化器"""

    class Meta:
        model = Enterprise
        fields = '__all__'



class RecruitSerializerez(serializers.ModelSerializer):
    """职位数据序列化器"""
    enterprise = Enterpriseserializer(Enterprise.objects.all())

    class Meta:
        model = Recruit
        fields = '__all_'
        # fields = ['id', 'jobname', 'salary', 'condition', 'education', 'type', 'city', 'createtime', 'enterprise']
